<%--
  Created by IntelliJ IDEA.
  User: 高万檬
  Date: 2020/8/7
  Time: 14:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.hqyj.education.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 高万檬
  Date: 2020/8/7
  Time: 8:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    /*basePath===http://localhost:8080/TestServlet04/*/
//     User user= (User) request.getSession().getAttribute("u");
//     int userRoleId=user.getUserRole();
%>
<html>
<head>
    <title>教师个人课程</title>
    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/admin.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap.min.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/jqPaginator.js"></script>
</head>
<body>
<div id="window"
     style="position: absolute;left: 30%;top:20%;width: 400px;height: 400px;background-color: #a6e1ec;display: none;">
    <center>
        <input type="hidden" name="id" id="id">
        <span>教师姓名：</span><input type="text" name="tname" id="tname" readonly="true"><br>
        <span>课程名称：</span><input type="text" name="lname" id="lname" readonly="true"><br>
        <span>地点：</span><input type="text" name="address" id="address" readonly="true"><br>
        <span>班级：</span><input type="text" name="classname" id="classname" readonly="true"><br>
        <span>开始时间：</span><input type="text" name="starttime" id="starttime" readonly="true"><br>
        <span>结束时间：</span><input type="text" name="endtime" id="endtime" readonly="true"><br>
    </center>
</div>
<table class="table table-hover" border="1" width="50%">
    <tr>
        <td>教师姓名</td>
        <td>课程名称</td>
        <td>地点</td>
        <td>班级</td>
        <td>开始时间</td>
        <td>结束时间</td>
    </tr>
    <tbody id="tb">
    </tbody>
</table>
<script>
    $(document).ready(function () {
        loadData();
    });

    function loadData() {
//jquery的ajax请求方法

        var roleId = <%=session.getAttribute("userRoleId")%>;
        var tid = <%=session.getAttribute("userId")%>;
        console.log(roleId);
        $.ajax({
            url: "<%=basePath%>teacher/queryTeacherLession",
            async: false,//同步请求（默认）
            type: "POST",
            dataType: "json",
            data: {"tid": tid, "roleid": roleId},
            success: function (data) {
                console.log(data);
//使用jquery形式遍历
// $.each(data.list, function (n, val) {
                $("#tb").html("");
                if (data.length > 0) {
                    //使用jquery形式遍历
                    $.each(data, function (n, val) {
                        var html = "";
                        html += "<tr>" +
                            "<td>" + val.tname + "</td>" +
                            "<td>" + val.coursename + "</td>" +
                            "<td>" + val.address + "</td>" +
                            "<td>" + val.cname + "</td>" +
                            "<td>" + val.lstarttime + "</td>" +
                            "<td>" + val.iendtime + "</td>" +
                            "<td>" + " " + "</td>" +
                            "<td>" +
                            "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='updateWindow(this)'>修改</button>" +
                            // "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='delWindow("+val.s_id+")'>删除</button>" +
                            "</td>" +
                            "</tr>";
                        $("#tb").append(html);
                    });
                } else {
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error: function () {
                alert("服务器出错！");
            }
        });

    }
</script>
</body>
</html>